/* // 写入基本操作
var fs = require('fs')
let content = '学习永无止境'
fs.writeFile('test.txt',content,{flag: 'a',encoding:'utf-8'},function(err){
    if(err) {
        console.log('写入失败')
    } else {
        console.log('写入成功')
    }
})
 */


 // 因为该写入操作的方式是异步操作，需要对写入进行封装

 function writeFiles(path,content) {
    return new Promise(function(resolve,reject) {
        var fs = require('fs')
        let contentStr = content + '\n'
        fs.writeFile(path,contentStr,{flag: 'a',encoding:'utf-8'},function(err){
            if(err) {
                console.log('写入失败')
                reject(err)
            } else {
                console.log('写入成功')
                resolve(err) // 这里其实不需要传参数的
            }
        })
    })
}

async function writeList () {
  await  writeFiles('writeTest.txt','我是谁')
  await  writeFiles('writeTest.txt','来着哪里')
  await  writeFiles('writeTest.txt','要去哪里')
}

writeList()